#include "statuswindow.h" 
#include <commctrl.h>
namespace win
{
	using sys::runtime_error;
	
	StatusWindow::StatusWindow()
	{
	}

	StatusWindow::~StatusWindow()
	{
	}

	void StatusWindow::Create(Window &parent, const int child_index)
	{
		_hwnd = CreateStatusWindow(
	   				WS_CHILD|WS_VISIBLE|CCS_BOTTOM|SBARS_SIZEGRIP,NULL,
	       			parent.GetHandle(),
	          		child_index);
		// Retrieve the default bar height
		RECT r;
		GetWindowRect(r);
		_bar_height = r.bottom - r.top;
	}

	void StatusWindow::AdjustLayout()
	{
		RECT r;
		::GetWindowRect(GetParentHandle(),&r);
	  	MoveWH(r.bottom-_bar_height,0,r.right,_bar_height);
	}

	void StatusWindow::SetParts(const int_array& widths)
	{
  		const int size = widths.size();
		if (size > 255)
			throw runtime_error("Widths must be less 255 than entries");
        int iStatusWidths[] = {200, 300, -1};
		::SendMessage(_hwnd,SB_SIMPLE,(WPARAM) FALSE,0);
		::SendMessage(_hwnd,SB_SETPARTS,size,(LPARAM) &widths[0]);
	}
	
	void StatusWindow::SetPartText(short part_index, const char * text)
	{
		::SendMessage(_hwnd,SB_SETTEXT , (WPARAM) part_index, (LPARAM) text);
	}

}
